package com.openroom.ui.component;

import com.jphotomanager.io.ImageLibrary;
import com.openroom.event.ApplicationEvent;
import com.openroom.event.EventManager;
import com.openroom.event.EventType;

public class SaturationControl extends EditControl {

    @Override
    protected int getStartValue() {
        return -100;
    }

    @Override
    protected int getEndValue() {
        return 100;
    }

    @Override
    protected int getInitialValue() {
        return 0;
    }

    @Override
    protected String getTextValue(int value) {
        try {
            return String.format("%.2f", value / 20.0f);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    @Override
    protected void onValueChanged(int value) {
        ImageLibrary.getInstance().increaseSaturation(value);
        EventManager.getInstance().publishEvent(
                new ApplicationEvent(EventType.RELOAD_IMAGE));
    }

    @Override
    protected int getValue(String text) {
        return (int) (Float.parseFloat(text) * 20);
    }
}
